package cn.ecnu.comment.controller;

import cn.ecnu.comment.service.CommentService;
import cn.ecnu.comment.vo.AdminCommentVo;
import cn.ecnu.comment.vo.CommentFrontVo;
import cn.ecnu.comment.vo.CommentVo;
import cn.ecnu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    //TODO: @Own(permission = Permission.COMMENT)
    @PostMapping("/add")
    public R addComment(@RequestBody CommentFrontVo vo) {
        CommentVo comment = commentService.addComment(vo);
        return R.ok().put("data", comment);
    }


    @GetMapping("/all")
    public R getAllComment(@RequestParam(value = "uid", required = false) Integer uid,
                           @RequestParam(value = "cid", required = false) Integer cid,
                           @RequestParam(value = "jid", required = false) Integer jid) {
        List<AdminCommentVo> result = commentService.getAllComment(uid, cid, jid);
        return R.ok().put("data", result);
    }


    // TODO: @Own(permission = Permission.VIEW)
    @GetMapping("/delete/{commentId}")
    public R deleteCommentById(@PathVariable("commentId") Integer commentId) {
        commentService.deleteById(commentId);
        return R.ok();
    }
}
